package com.reactnativestudy.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

import com.facebook.react.ReactInstanceManager;
import com.facebook.react.ReactRootView;
import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler;
import com.reactnativestudy.utils.ReactViewCache;

public class TestActivity extends AppCompatActivity implements DefaultHardwareBackBtnHandler {

//    {"name":"Study","hash":"bbbbbb","entry":"bundle-bussiness.js","bundle":"https:\/\/gitee.com\/chengting\/ReactNativeStudy\/raw\/master\/bundle-android\/bussiness.zip","dependencies":[{"name":"COMMON","hash":"cccccc","entry":"bundle-common.js","bundle":"https:\/\/gitee.com\/chengting\/ReactNativeStudy\/raw\/master\/bundle-android\/common.zip"}]}`
    private static final String TAG = "TestActivity";
    private ReactRootView getReactRootView(){
        return ReactViewCache.getInstance().getDelegate(this,"entry");
    }
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(getReactRootView());
    }

    private ReactInstanceManager getReactInstanceManager(){
        return getReactRootView().getReactInstanceManager();
    }

    @Override
    protected void onResume() {
        super.onResume();
       getReactInstanceManager().onHostResume(this,   this);
    }

    @Override
    protected void onPause() {
        super.onPause();
        getReactInstanceManager().onHostPause(this);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        getReactInstanceManager().onHostDestroy(this);
    }

    @Override
    public void onBackPressed() {
        if(getReactInstanceManager() != null){
            getReactInstanceManager().onBackPressed();
        }else {
            super.onBackPressed();
        }


    }

    @Override
    public void invokeDefaultOnBackPressed() {
        super.onBackPressed();
    }
}
